package com.example.testandroid.activity;

import java.util.Timer;
import java.util.TimerTask;

import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.widget.TextView;

import com.example.testandroid.R;

public class NeonLightActivity extends Activity {
	private int currentColor = 0;
	
	final int[] colors = new int []{
		R.color.c1,
		R.color.c2,
		R.color.c3,
		R.color.c4,
		R.color.c5,
		R.color.c6,
		R.color.c7
	};
	
	final int[] names=new int[]{
		R.id.View01,
		R.id.View02,	
		R.id.View03,	
		R.id.View04,	
		R.id.View05,	
		R.id.View06,	
		R.id.View07,	
			
	};
	
	TextView[] views = new TextView[7];
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_neonlight);
		
		for (int i=0;i<7;i++){
			views[i] = (TextView) findViewById(names[i]);
		}
		final Handler handler = new Handler(){

			@Override
			public void handleMessage(Message msg) {
				if(msg.what == 0x1122){
					for (int i = 0; i < 7 -currentColor; i++){
						views[i].setBackgroundResource(colors[i+currentColor]);
					}
					for(int i = 7-currentColor, j=0; i < 7; i++, j++){
						views[i].setBackgroundResource(colors[j]);
					}
				}
				super.handleMessage(msg);
			}
			
		};
		
		new Timer().schedule(new TimerTask() {
			
			@Override
			public void run() {
				currentColor++;
				if(currentColor >= 6){
					currentColor=0;
				}
				Message m = new Message();
				m.what = 0x1122;
				handler.sendMessage(m);
			}
		}, 0, 100);
	}


}
